<HTML><HEAD><TITLE>expand_macros(?Term, -TransTerm)</TITLE>
</HEAD><BODY>[ <A HREF="index.html">Term I/O</A> | <A HREF="../../index.html">Reference Manual</A> | <A HREF="../../fullindex.html">Alphabetic Index</A> ]
<H1>expand_macros(?Term, -TransTerm)</H1>
Apply macro transformations to Term
<DL>
<DT><EM>Term</EM></DT>
<DD>A term.
</DD>
<DT><EM>TransTerm</EM></DT>
<DD>A variable.
</DD>
</DL>
<H2>Description</H2>
    Applies macro-transformations to Term, if any are visible in the
    caller module. If no transformation is visible, TransTerm is identical
    to Term.
    <P>
    Normally, macro expansion is performed implicitly by the parser, i.e.
    when using either the compiler or term-input builtins like read/1,2,
    read_term/2,3 or readvar/2,3.
    <P>
    For certain meta-programming applications, where one needs to work with
    the original unexpanded form of the input, this is undesirable.
    In such cases, macro-expansion can be switched off during reading
    and later performed explicitly using expand_macros/2.
    <P>
    For reading input without macro expansion, set the stream-flag
    macro_expansion to off before reading (see set_stream_property/3
    or open/4), or use the facilities of the library(source_processor).

<H3>Modes and Determinism</H3><UL>
<LI>expand_macros(?, -) is det
</UL>
<H3>Modules</H3>
This predicate is sensitive to its module context (tool predicate, see @/2).
<H2>Examples</H2>
<PRE>
    % Given the program:

	t(water, wine).
	:- local macro(water, t/2, []).


    % Implicit macro expansion by read/1:
    ?- open(string("water"),read,S),
    	read(S,X),
	close(S).
    X = wine
    yes.

    % Implicit macro expansion switched off:
    ?- open(string("water"),read,S,[macro_expansion(off)]),
    	read(S,X),
	close(S).
    X = water
    yes.

    % Explicit macro expansion:
    ?- open(string("water"),read,S,[macro_expansion(off)]),
    	read(S,X),
	expand_macros(X,Y),
	close(S).
    X = water
    Y = wine
    yes.

    % All occurrences are expanded:
    ?- open(string("[water,beer,fizzy(water)]"),read,S,[macro_expansion(off)]),
    	read(S,X),
	expand_macros(X,Y),
	close(S).
    X = [water, beer, fizzy(water)]
    Y = [wine, beer, fizzy(wine)]
    yes.
</PRE>
<H2>See Also</H2>
<A HREF="../../kernel/syntax/macro-3.html">macro / 3</A>, <A HREF="../../kernel/compiler/expand_clause-2.html">expand_clause / 2</A>, <A HREF="../../kernel/compiler/expand_goal-2.html">expand_goal / 2</A>, <A HREF="../../kernel/iostream/open-4.html">open / 4</A>, <A HREF="../../kernel/iostream/set_stream_property-3.html">set_stream_property / 3</A>, <A HREF="../../lib/source_processor/index.html">library(source_processor)</A>, <A HREF="../../kernel/syntax/portray-3.html">portray / 3</A>, <A HREF="../../kernel/ioterm/portray_term-3.html">portray_term / 3</A>
</BODY></HTML>
